<?php

namespace App\Console\Commands;

use App\Models\ClockRecord;
use App\Models\Question;
use App\Models\QuestionMember;
use App\Models\Record;
use Illuminate\Console\Command;

class voteCount extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:voteCount';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '投票数的统计脚本';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //处理问题
        $question = Question::query()->whereIn('status', [Question::QUESTION_PASS_SMALL, Question::QUESTION_PASS_BIG])->get()->toArray();

        foreach ($question as $key => $value){
            $questionMember = QuestionMember::query()->where('question_id', $value['question_id'])->count();
            Question::query()->where('question_id', $value['question_id'])->update(['num' => $questionMember]);
        }
    }
}
